The React Mega-Tutorial by Grinberg Miguel

The React Mega-Tutorial by Grinberg Miguel

Author:Grinberg, Miguel
Language: eng
Format: epub
Publisher: Miguel Grinberg
Published: 2022-04-22T00:00:00+00:00


To associate this reference with an element rendered to the page, the ref attribute is added to the element when it is rendered.

export default function MyForm() { const usernameField = useRef(); return ( <form> <input type="text" ref={usernameField} /> </form> ); }

The reference object has a current attribute that can be used in side effect functions and event handlers to access the actual DOM object associated with the component:

export default function MyForm() { const usernameField = useRef(); const onSubmit = (ev) => { ev.preventDefault(); alert('Your username is: ' + usernameField.current.value); }; return ( <form onSubmit={onSubmit}> <input type="text" ref={usernameField} /> </form> ); }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.